<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2012.03.17.
   学装修($$)*/

!defined('Q_PATH') && exit;

class Index_C_Controller extends InitController{

	public function index(){
		// 读取缓存
		Core_Extend::loadCache('slide');
		
		// 读取资讯
		$sCid=trim(Q::G('cid','G'));
		if($sCid){
			$nCid=Jiaju_Extend::getXue($sCid);
			if(!$nCid){
				$this->page404();
			}
			$sPTitle=Model::F_('homefreshcategory','homefreshcategory_id=?',$nCid)->getColumn('homefreshcategory_name');
			if(!$sPTitle){
				$this->page404();
			}
		}else{
			$nCid=0;
			$sPTitle='';
		}

		$arrWhere=array();
		$arrWhere['A.homefresh_status']=1;
		if($nCid){
			$arrWhere['A.homefreshcategory_id']=$nCid;
		}

		$nTotal=Model::F_('homefresh','@A')->where($arrWhere)->getCounts();

		// 分页显示
		$sPageurl='';
		if($nCid){
			$sPageurl='@xue~@jiaju://category/'.$sCid.'_{page}';
		}else{
			$sPageurl='@xue~@jiaju://list@?page={page}';
		}

		$oPage=Page::RUN($nTotal,10,$sPageurl);

		$arrHomefreshs=Model::F_('homefresh','@A')
			->setColumns('A.homefresh_id,A.homefresh_title,A.user_id,A.create_dateline,A.homefresh_attribute,A.homefresh_commentnum,A.homefresh_goodnum,A.homefresh_viewnum,A.homefresh_type,A.homefresh_thumb,A.homefreshcategory_id')
			->join(Q::C('DB_PREFIX').'user AS B','B.user_name','A.user_id=B.user_id')
			->joinLeft(Q::C('DB_PREFIX').'homefreshcategory AS C','C.homefreshcategory_name','A.homefreshcategory_id=C.homefreshcategory_id')
			->joinLeft(Q::C('DB_PREFIX').'site AS J','J.site_domain','A.site_id=J.site_id')
			->where($arrWhere)
			->order('A.create_dateline DESC')
			->limit($oPage->S(),$oPage->N())
			->getAll();

		$sGoodCookie=Q::cookie('homefresh_goodnum');
		$arrGoodCookie=explode(',',$sGoodCookie);

		Core_Extend::getSeo($this,array(
			'title'=>($sPTitle?$sPTitle.'_':'').$GLOBALS['_option_']['site_name'].'装修学堂频道_装修知识_装修心得_装修灵感_装修搭配',
			'keywords'=>($sPTitle?$sPTitle.',':'').$GLOBALS['_option_']['site_name'].'装修学堂频道,装修知识,装修心得,装修灵感,装修搭配',
			'description'=>$GLOBALS['_option_']['site_name'].$sPTitle.'装修学堂频道，主要提供装修知识大全、装修常识分享等有关装修的经验心得、本频道包含学装修、找装修灵感、学装修搭配、选择装修材料等相关装修知识，学习更多装修家装有关知识，请访问'.$GLOBALS['_option_']['site_name'].'学堂频道。',
		),true,false,false);
		
		$this->assign('sPageNavbar',$oPage->P(array('id'=>'pagination','style'=>'li','current'=>'active')));
		$this->assign('arrGoodCookie',$arrGoodCookie);
		$this->assign('arrHomefreshs',$arrHomefreshs);
		$this->assign('nCid',$nCid);
		$this->assign('sCid',$sCid);
		$this->assign('sPTitle',$sPTitle);
		$this->assign('arrSlides',$GLOBALS['_cache_']['slide']);
		$this->display('xue+index');
	}

}
